import { rank_sort,rank_sort_list } from "@/api";

const state = {
    rank_sort_1:[],
    rank_sort_2:[],
    rank_sort_3:[],
    rank_sort_4:[],
    rank_sort_5:[],
    rank_sort_list:{},
    
    
};
const getters = {

};
const mutations = {
    RANK_SORT(state,data){
        for(var i in data.info){
            data.info[i].album_img_9=data.info[i].album_img_9.replace('/{size}/','/')
            data.info[i].banner_9=data.info[i].banner_9.replace('/{size}/','/')
            if(data.info[i].album_img_9==""){
                data.info[i].album_img_9=data.info[i].banner_9
            }            
            if(data.info[i].classify==1){
                state.rank_sort_1.push(data.info[i])
            }else if(data.info[i].classify==2){
                state.rank_sort_2.push(data.info[i])
            }else if(data.info[i].classify==3){
                state.rank_sort_3.push(data.info[i])
            }else if(data.info[i].classify==4){
                state.rank_sort_4.push(data.info[i])
            }else if(data.info[i].classify==5){
                state.rank_sort_5.push(data.info[i])
            }
            
        }
    },
    RANK_SORT_LIST(state,data){
        state.rank_sort_list=data
    }

};
const actions = {
    //排行榜分类
    async rank_sort({commit}){
        let result=await rank_sort()
        let result_i=JSON.parse(result.slice(23,-21))
        if(result_i.status==1){
            commit('RANK_SORT',result_i.data)
        }else{
            return Promise.reject(new Error('faile'))
        }
    },
    //排行榜分类详情列表
    async rank_sort_list({commit},{type,size,page,cid,rankid}){
        let result=await rank_sort_list(type,size,page,cid,rankid)
        let result_i=JSON.parse(result.slice(23,-21))
        if(result_i.status==1){
            commit('RANK_SORT_LIST',result_i.data)
        }else{
            return Promise.reject(new Error('faile'))
        }
        
    }

};
const modules = {

};

export default {
    state,
    getters,
    mutations,
    actions,
    modules
}